package com.tk.exam.web.admin;

import com.tk.exam.domain.TkClass;
import com.tk.exam.http.Response;
import com.tk.exam.service.ClassService;
import com.tk.exam.utils.PageInfo;
import com.tk.exam.vo.StudentVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: xujg
 * @Description: TODO
 * @date: 2019-06-17 17:01
 */
@RestController
@RequestMapping("/tk/exam/admin")
public class ClassManagement {

    @Autowired
    private ClassService classService;

    @GetMapping("/class/getList")
    public Response getList(){
        List<TkClass> tkClasses = classService.getList();
        return Response.succeed().put("classList",tkClasses);
    }
    @PostMapping("/class/edit")
    public Response editClass(@RequestBody TkClass tkClass){
        if(StringUtils.isEmpty(tkClass.getId()+"")||StringUtils.isEmpty(tkClass.getClassName())){
            return Response.fail("缺少参数");
        }
        int i = classService.editClass(tkClass);
        return i ==1?Response.succeed():Response.fail("编辑班级失败");

    }

    @PostMapping("/class/add")
    public Response addClass(@RequestBody TkClass tkClass){
        if(StringUtils.isEmpty(tkClass.getClassName())){
            return Response.fail("缺少参数");
        }
        int i = classService.addClass(tkClass);
        return i ==1?Response.succeed():Response.fail("新增班级失败");

    }

    @PostMapping("/class/delete")
    public Response deleteClass(String[] classIds){
        if(classIds==null||classIds.length==0){
            return Response.fail("classIds不能为空");
        }
        int i = classService.deleteClass(classIds);
        return i ==1?Response.succeed():Response.fail("删除班级失败");
    }
}
